package logic

import (
	"context"
	"errors"
	"rikao8/houserpc/models/mysql"

	"rikao8/houserpc/houserpc"
	"rikao8/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *houserpc.ShowRequest) (*houserpc.ShowResponse, error) {
	// todo: add your logic here and delete this line

	var h mysql.House
	err := h.Show(int(in.Id))
	if err != nil {
		return nil, errors.New("详情展示失败")
	}
	return &houserpc.ShowResponse{Id: int32(h.ID), Name: h.Name, Address: h.Address, Area: int32(h.Area), Price: float32(h.Price)}, nil
}
